package main
// 07/10/13
// create rpm spec from list+.lst
import (
	"bufio"
	"flag"
	"fmt"
	"os"
)

const (
	usage = "lstspc -v=2 -r=1 -a=1 -n=DwmLst lst+.lst"
)

func main() {
	nam := flag.String("n", "Dwm", usage)
	ver := flag.Int("v", 0, usage)
	rel := flag.Int("r", 0, usage)
	add := flag.Int("a", 1, usage)

	flag.Parse()
	if flag.NArg() > 0 {

		fmt.Printf("Name:%s\n", *nam)
		fmt.Printf("Summary:%s\n", *nam)
		fmt.Printf("Version:%d\n", *ver)
		fmt.Printf("Release:%d\n", *rel)
		fmt.Printf("License:distributable\n")
// head -n 1 /usr/share/doc/rpm-*/GROUPS
		fmt.Printf("Group:Amusements/Games\n")
		fmt.Printf("BuildArch:noarch\n")

		path := flag.Arg(0)

		fin, err := os.Open(path)
		if err != nil {
			fmt.Fprintf(os.Stderr, "The file %s does not exist!\n", path)
			return
		}
		defer fin.Close()
		desc := ""
		scanner := bufio.NewScanner(fin)
		i := 0
		for scanner.Scan() {
			l := scanner.Text()
			if *add == 1 {
				fmt.Printf("Requires:%s\n", l)
			} else if *add == 0 {
				fmt.Printf("Obsoletes:%s\n", l)
			} else {
				panic("add is either 1 or 0")
			}
			if i == 0 {
				desc = l
			} else {
				desc = desc + "," + l
			}
			i =+ 1
		}
		fmt.Printf("%%description\n%s\n", desc)
		fmt.Printf("%%prep\n")
		fmt.Printf("%%build\n")
		fmt.Printf("%%clean\n")
		fmt.Printf("%%install\n")
		fmt.Printf("%%post\n")
		fmt.Printf("%%files\n")
		fmt.Printf("%%changelog\n")

	} else {
		fmt.Println(usage)
	}
}
/*
		donmoore@utdallas.edu


		This file is part of lstspc

    lstspc.go is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    lstspc.go is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with lstspc.go.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	http://www.rpm.org/wiki/PackagerDocs/ArchDependencies
	i686, use list like pkg(x86-32)
*/